package com.prg.util;

import org.apache.commons.dbcp.BasicDataSource;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 14-6-2
 * Time: 下午4:28
 * To change this template use File | Settings | File Templates.
 */
public class DBConnectionDBCP {

    private static Properties props = null;
    private static BasicDataSource ds = new BasicDataSource();

    static {
        props = new Properties();
        try {
            props.load(DBConnection.class.getResourceAsStream("/jdbc.properties"));
        } catch (IOException e1) {
            e1.printStackTrace();
        }

        ds.setDriverClassName(props.getProperty("idbase.driverClassName"));
        ds.setUrl(props.getProperty("idbase.url"));
        ds.setUsername(props.getProperty("idbase.username"));
        ds.setPassword(props.getProperty("idbase.password"));
        ds.setInitialSize(Integer.valueOf("10"));
        ds.setMaxActive(Integer.valueOf("10"));
    }

    public static Connection getConnection() throws SQLException {
        return ds.getConnection();
    }
    public static  BasicDataSource getDs(){
        return ds;
    }
}
